<template>
  <div class="app-container">
    <!-- 搜索相关区域 -->
    <div class="filter-container">

      <el-form :inline="true" :model="searchParam" class="demo-form-inline">
        <el-form-item label="商品名称:">
          <el-input
            v-model="searchParam.seriesName"
            size="mini"
            placeholder="商品名称模糊查询"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click="getPage()"
          >查询
          </el-button>
          <el-button
            size="mini"
            icon="el-icon-refresh"
            @click="() => {this.searchParam = {}, this.getPage()}"
          >重置
          </el-button>
        </el-form-item>
      </el-form>
      <el-button size="mini" icon="el-icon-plus" type="primary" class="filter-item" @click="addOrUpdateHandle()">
        创建
      </el-button>
    </div>

    <!-- 列表相关区域 -->
    <el-table
      v-loading="pageLoading"
      :data="pageVO.list"
      border
      fit
      highlight-current-row

      style="width: 100%;"
    >
      <el-table-column
        type="selection"
        align="center"
        width="60">
      </el-table-column>
      <el-table-column label="序号" prop="prodName" align="center">
        <template slot-scope="{row}">
          <span>{{ row.index }}</span>
        </template>
      </el-table-column>

      <el-table-column label="系列名称" prop="platformRate" align="center">
        <template slot-scope="{row}">
          <span>{{ row.seriesName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="图片" prop="mainImg" align="center">
        <template slot-scope="{row}">
          <img :src="resourcesUrl+row.seriesImg" class="img">
        </template>
      </el-table-column>
      <!-- 创建时间 -->
      <el-table-column label="创建" prop="createTime" align="center">
        <template slot-scope="{row}">
          <span>{{ row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="text" @click="addOrUpdateHandle(row.id)">
            编辑
          </el-button>
          <el-button type="text" @click="ondele(row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页条 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageQuery.pageNum"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageQuery.pageSize"
      :total="pageVO.total"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getPage()"/>

  </div>
</template>

<script>
import AddOrUpdate from './add-or-update.vue'

export default {
  name: '',
  components: {AddOrUpdate},
  data () {
    return {
      resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
      // 查询的参数
      pageQuery: {
        pageSize: 10,
        pageNum: 1

      },
      // 返回参数
      pageVO: {
        list: [], // 返回的列表
        total: 0, // 一共多少条数据
        pages: 0 // 一共多少页
      },
      // loading
      pageLoading: true,
      // 查询参数
      searchParam: {
        seriesName: '',
      },
      autoAuditSwitch: false,
      ids: [],
      addOrUpdateVisible: false
    }
  },
  mounted () {
    //   this.getAudit()
    this.getPage()
  },
  methods: {

    handleSizeChange (val) {
      this.pageQuery.pageSize = val
      this.getPage()
    },
    handleCurrentChange (val) {
      this.pageQuery.pageNum = val
      this.getPage()
    },
    getPage () {
      this.pageLoading = true
      this.$http({
        url: this.$http.adornUrl('/platform/spuSeries/ua/getList'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign({...this.pageQuery, ...this.searchParam}
          )
        )
      }).then(({data}) => {
        this.pageLoading = false
        this.pageVO.list = data.list
        this.pageVO.total = data.total
      })
    },
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    ondele (imgId) {
      this.$confirm('确定进行删除操作?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => this.dele(imgId))
    },
    dele (id) {
      this.$http({
        url: this.$http.adornUrl('/platform/spuSeries/dele'),
        method: 'delete',
        data: this.$http.adornData({id: id})
      }).then(({data}) => {
        this.$message({
          message: '操作成功',
          type: 'success',
          duration: 1500,
          onClose: () => this.getPage()
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  .brand-logo-img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 200px;
  }
}

.img {
  width: 240px;
}
</style>
